package cn.edu.sziit.bbs.controller;

import cn.edu.sziit.bbs.model.Post;
import cn.edu.sziit.bbs.model.Reply;
import cn.edu.sziit.bbs.service.PostService;
import cn.edu.sziit.bbs.service.ReplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpSession;
import java.util.List;

//postContent.jsp
@Controller
public class PostContentController {

    @Autowired
    private PostService postService;
    @Autowired
    private ReplyService replyService;

    /**
     * 跳转到对应postId帖子详细页面
     *
     * @param postId
     * @param session
     * @return
     */
    @RequestMapping(value = "/postContent", method = RequestMethod.GET)
    public String postContentShow(Integer postId, HttpSession session) {
        Post post = postService.selectByPrimaryKey(postId);
        List<Reply> replies = replyService.selectByPostId(postId);
        session.setAttribute("post", post);
        session.setAttribute("replies", replies);
        return "postContent";

    }

}
